class Factory:
    def __init__(self):
        pass
    def getSoundCardHandle(self, id):
        return LinuxSoundCard(id)
    

class AbstractSoundCard:
    def readSample(self, length):
        raise("Not implemented!")
    def writeSample(self, sample):
        raise ("Not implemented!")
    def setInputVolume(self, value):
        raise("Not implemented!")
    def setOutPutVolume(self, value):
        raise("Not implemented")
    def getSampleFrequency(self):
        raise("Not implemented")

class LinuxSoundCard(AbstractSoundCard):
    
    
    def __init__(self, id):
        import ossaudiodev
        self.__sampleFrequency = 44100
        
        soundcard = "/dev/audio"
        if id > 0:
            soundcard = soundcard + str(id)
        
        self.__sndcardhandle = ossaudiodev.open(soundcard, "rw")
        self.__sndcardhandle.setparameters(ossaudiodev.AFMT_S16_LE, 2, self.__sampleFrequency)
    def readSample(self, length):
        return self.__sndcardhandle.read(length)
        pass
    def writeSample(self, sample):
        self.__sndcardhandle.write(sample)
    
    def getSampleFrequency(self):
        return self.__sampleFrequency
    
    